//
// Created by judasnow on 27/12/2017.
//

#include <algorithm>
#include <iomanip>
#include <ios>
#include <iostream>
#include <string>
#include <vector>

using std::cin;
using std::sort;
using std::cout;
using std::string;
using std::vector;
// 设置输出流的精度
using std::setprecision;

int main() {
    cout << "Please enter your first name: ";
    string name;
    cin >> name;
    cout << "Hello, " << name << "!" << std::endl;

    cout << "Input midterm, final exam:";
    double midterm, final;
    cin >> midterm >> final;

    cout << "Enter all your homework grades,"
            "followed by end-of-file: ";
    vector<double> homework;
    double x;
    while (cin >> x) {
        homework.push_back(x);
    }

    typedef vector<double>::size_type vec_sz;
    vec_sz size = homework.size();
    if (size == 0) {
        cout << std::endl << "You must enter your grades."
                             "Please try again." << std::endl;
    }

    sort(homework.begin(), homework.end());

    vec_sz mid = size / 2;
    double median;
    median = size % 2 == 0 ? (homework[mid] + homework[mid-1]) / 2
                            : homework[mid];

    std::streamsize prec = cout.precision();
    cout << "You final grade is " << setprecision(3)
                                  << 0.2 * midterm + 0.4 * final + 0.4  * median
                                  << setprecision(prec) << std::endl;

    return 0;
}
